package com.mrd.gtimp.business.entity;

import com.mrd.gtimp.base.entity.Company;
import com.mrd.gtimp.v2.fund.FundFinancialTypeEnum;

import org.hibernate.annotations.GenericGenerator;

import java.io.Serializable;
import java.text.DecimalFormat;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;

/**
 * @author luob
 */
@Entity(name = "T_BIZ_FUND_FLOW")
public class FundFlow implements Serializable {
    private static final long serialVersionUID = 1L;
    /**
     * id
     */
    @Id
    @GeneratedValue(generator = "paymentableGenerator")
    @GenericGenerator(name = "paymentableGenerator", strategy = "uuid")
    @Column(name = "ID")
    private String id;

    /**
     * 账户所属公司
     */
    @ManyToOne
    @JoinColumn(updatable = false, name = "COM_ID")
    private Company owner;
    /**
     * 流水金额,入账金额(元)
     */
    @Column(updatable = false, name = "AMOUNT")
    private double amount;

    public double getFinancialAmount() {
        if (FundFinancialTypeEnum.OUT.toString().equals(financialType)) {
            return amount * (-1);
        } else {
            return amount;
        }
    }

    /**
     * 财务类型
     */
    @Column(updatable = false, name = "FINANCIAL_TYPE")
    private String financialType;
    /**
     * 收支类型
     */
    @Column(updatable = false, name = "IE_TYPE")
    private String ietype;
    /**
     * 账户余额,账户结余(元)
     */
    @Column(updatable = false, name = "BALANCE")
    private double balance;
    /**
     * 备注
     */
    @Column(name = "REMARK")
    private String remark;
    /**
     * 业务单证编号
     */
    @Column(name = "BILL_NO")
    private String billNo;

    /**
     * 创建时间，充值时间
     */
    @Column(name = "REG_DATE", updatable = false)
    private Date regDate;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Company getOwner() {
        return owner;
    }

    public void setOwner(Company ownner) {
        this.owner = ownner;
    }

    public double getAmount() {
        return amount;
    }

    public void setAmount(double amount) {
        this.amount = amount;
    }

    public String getFinancialType() {
        return financialType;
    }

    public void setFinancialType(String financialType) {
        this.financialType = financialType;
    }

    public String getIetype() {
        return ietype;
    }

    public void setIetype(String ietype) {
        this.ietype = ietype;
    }

    @Transient
    private DecimalFormat df   = new DecimalFormat("######0.00");

    public double getBalance() {
        String _balance = df.format(balance);
        return  Double.parseDouble(_balance);
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Date getRegDate() {
        return regDate;
    }

    public void setRegDate(Date regDate) {
        this.regDate = regDate;
    }

    @Override
    public String toString() {
        return "FundFlow [id=" + id + ", ownner=" + owner + ", amount=" + amount
                + ", financialType=" + financialType + ", ietype=" + ietype + ", balance="
                + balance + ", remark=" + remark + ", billNo=" + billNo + ", registrant="
                + ", regDate=" + regDate + "]";
    }

    public String getBillNo() {
        return billNo;
    }

    public void setBillNo(String billNo) {
        this.billNo = billNo;
    }
}
